package com.kc.web.controller.business;

import com.kc.business.domain.BizOrderAddress;
import com.kc.business.service.IBizOrderAddressService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * TODO
 * 收/发货地址管理
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/10/13
 */
@RestController
@RequestMapping("/business/orderAddress")
public class BizOrderAddressController extends BaseController {
    @Resource
    private IBizOrderAddressService orderAddressService;

    /**
     * 获取地址列表
     */
    @PreAuthorize("@ss.hasPermi('business:orderAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizOrderAddress orderAddress) {
        startPage();
        return getDataTable(orderAddressService.getList(orderAddress));
    }

    /**
     * 新增地址
     */
    @PreAuthorize("@ss.hasPermi('business:orderAddress:add')")
    @Log(title = "地址管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizOrderAddress orderAddress) {
        return toAjax(orderAddressService.add(orderAddress));
    }

    /**
     * 修改地址
     */
    @PreAuthorize("@ss.hasPermi('business:orderAddress:edit')")
    @Log(title = "地址管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizOrderAddress orderAddress) {
        return toAjax(orderAddressService.edit(orderAddress));
    }

    /**
     * 删除地址
     */
    @PreAuthorize("@ss.hasPermi('business:orderAddress:remove')")
    @Log(title = "地址管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderAddressId}")
    public AjaxResult remove(@PathVariable Integer orderAddressId) {
        return toAjax(orderAddressService.delete(orderAddressId));
    }

}
